#include <sys_head.h>

typedef struct msgbuf
{
    long type;//消息的类型
    char buf[128];//消息的正文
}MSGBUF;

int main(int argc, char const *argv[])
{
    // ftok函数会把我们出入的两个参数通过某种算法生成一串秘钥
    key_t key = ftok("/home/student/桌面",1000);
    //创建/打开消息队列
    int id = msgget(key,0666);
    //从消息队列中取出1000号消息，把消息正文存入参数二的buf中
    MSGBUF msgbuf;
    msgrcv(id,&msgbuf,sizeof(msgbuf.buf),1000,0);
    printf("收到消息为:%s\n",msgbuf.buf);

    //释放消息队列给系统
    msgctl(id,IPC_RMID,NULL);
    return 0;
}
